<template>
	<view>
		<an-nav-bar title="选择优惠券"> </an-nav-bar>
		<view class="order-list" v-if="couponList.length">
			<view class="list" v-for="(item,index) in couponList" :key="index" @click="gotoUrl(item)">
				<view class="top">
					<view class="left">
						<view class="offset">
							<view class="currency"></view>
							<view class="money">{{item.discountPrice}}</view>
						</view>
					</view>
					<view class="right">
						<view class="name">{{item.couponName}}</view>
						<view class="price">免费领取</view>
						<view class="rule">使用规则：仅可在指定项目使用</view>
					</view>
					<view class="visit"></view>
				</view>
				<view class="cut"></view>
				<view class="bottom">
					<view class="time">有效期：{{item.validityPeriodStart}}-{{item.validityPeriodStart}}</view>
					<!-- <button class="btn">去使用</button> -->
				</view>
			</view>
		</view>
		<view class="order-list" v-if="!couponList.length">
			<view class="null-box">
				<image src="/static/null.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				couponList: []
			};
		},
		onLoad() {

		},
		onShow() {
			this.getList()
		},
		methods: {
			onOrderStatus(idx) {
				this.orderStatusIdx = idx
				this.couponList = []
				this.getList()
			},
			gotoUrl(item) {
				let pages = getCurrentPages() // 获取页面栈
				console.log()
				if (pages.length > 1 && pages[pages.length - 2].route == "pages/submitOrder/submitOrder") {
					let prePage = pages[pages.length - 2] //获取上一页
					prePage.$vm.setCoupon(item)
				}
				// 返回上一页 delta返回的页面数 如果delta大于现有页面数，则返回首页
				uni.navigateBack({
					delta: 1
				})
			},
			getList() {
				this.$http.get('/app/customer/customerCoupon/list', {
					status: 1
				}).then(res => {
					this.couponList = res.rows
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #ffffff;
	}
</style>
<style lang="scss">
	.order-list {
		width: 100%;
		padding: 0 30rpx;
		background-color: #fff;
		padding-bottom: 30rpx;
		box-sizing: border-box;

		.list {
			width: 100%;
			height: 270rpx;
			margin-top: 30rpx;
			background-color: #fff;
			border-radius: 10rpx;
			box-shadow: 0 0 54rpx 0 rgba(187, 184, 184, .8);
			position: relative;
			overflow: hidden;

			.bottom {
				float: left;
				width: 100%;
				height: 100rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: flex-start;

				.time {
					float: left;
					width: 520rpx;
					height: 100rpx;
					line-height: 100rpx;
					font-size: 20rpx;
					font-weight: 300;
					color: #999;
					text-align: center;
					text-overflow: ellipsis;
				}

				.btn {
					float: right;
					width: 180rpx;
					height: 60rpx;
					line-height: 60rpx;
					background: linear-gradient(90deg, #d7b075, #aa8050);
					border-radius: 30rpx;
					font-size: 30rpx;
					color: #f8f8f8;
					text-align: center;
				}
			}

			.cut {
				float: left;
				width: 670rpx;
				height: 0;
				border-top: 2rpx dashed #eee;
				position: absolute;
				top: 170rpx;
				left: 10rpx;
				content: "";
				background-color: #fff;
				z-index: 99;
				box-sizing: border-box;
			}

			.top {
				float: left;
				width: 100%;
				height: 170rpx;
				position: relative;

				.left {
					float: left;
					width: 150rpx;
					height: 150rpx;
					margin-left: 20rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;

					.offset {
						display: flex;

						.currency {
							position: relative;
							margin-right: 30rpx;
							font-size: 34rpx;

							&::after {
								position: absolute;
								top: 60%;
								-webkit-transform: translateY(-50%);
								transform: translateY(-50%);
								content: "¥";
								display: block;
								color: #666;
								font-weight: 700;
							}
						}

						.money {
							color: #f208fd;
							font-size: 60rpx;
							font-weight: 700;
						}
					}
				}

				.right {
					float: right;
					width: 480rpx;
					height: 170rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					margin-right: 20rpx;

					.name {
						float: left;
						width: 480rpx;
						height: 60rpx;
						line-height: 60rpx;
						font-size: 14px;
						font-weight: 600;
						color: #333;
						text-overflow: ellipsis;
						text-align: left;
					}

					.price,
					.rule {
						float: left;
						width: 100%;
						line-height: 36rpx;
						font-size: 18rpx;
						font-weight: 300;
						color: #333;
						text-overflow: ellipsis;
						text-align: left;
					}
				}
			}

			&::before {
				width: 20rpx;
				height: 20rpx;
				position: absolute;
				top: 160rpx;
				left: -10rpx;
				content: "";
				background-color: rgba(187, 184, 184, .5);
				border-radius: 10rpx;
				z-index: 99;
			}

			&::after {
				width: 20rpx;
				height: 20rpx;
				position: absolute;
				top: 160rpx;
				right: -10rpx;
				content: "";
				background-color: rgba(187, 184, 184, .5);
				border-radius: 10rpx;
				z-index: 99;
			}
		}
	}

	.order-type {
		width: 100%;
		height: 100rpx;
		background-color: #ffffff;
		position: fixed;
		top: calc(var(--status-bar-height) + 88rpx);
		left: 0;
		padding: 0 30rpx;
		box-sizing: border-box;
		justify-content: space-between;
		z-index: 999;

		.order-line {
			width: 180rpx;
			height: 4rpx;
			background: linear-gradient(90deg, #d7b075, #aa8050);
			position: absolute;
			bottom: 0rpx;
			transition: all .5s;
		}

		.order {
			width: 230rpx;
			text-align: center;
			height: 40rpx;
			font-size: 28rpx;
			font-weight: 500;
			color: #666;
			line-height: 40rpx;
		}

		.order-check {
			font-weight: 700;
			color: #aa8050;
		}
	}
</style>
